<template>
    <div class="container-content">
        <el-form
            ref="elForm"
            :model="formData"
            :rules="rules"
            size="medium"
            label-width="100px"
        >
            <el-form-item
                label-width="200px"
                label="金额精度"
                prop="amountAccuracy"
            >
                <el-input
                    v-model="formData.amountAccuracy"
                    placeholder="请输入金额精度"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <!-- <el-form-item label-width="200px" label="币别编码" prop="code">
                <el-input
                    v-model="formData.code"
                    placeholder="请输入币别编码"
                    clearable
                    :style="{ width: '100%' }"
                ></el-input>
            </el-form-item> -->
            <el-form-item
                label-width="200px"
                label="币别名称"
                prop="currencyName"
            >
                <el-input
                    v-model="formData.currencyName"
                    placeholder="请输入币别名称"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="货币代码"
                prop="currencySymbol"
            >
                <el-input
                    v-model="formData.currencySymbol"
                    placeholder="请输入货币代码"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="数据状态"
                prop="dataStatus"
            >
                <el-select
                    v-model="formData.dataStatus"
                    placeholder="请选择数据状态"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in dataStatusOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="是否禁用"
                prop="isDisabled"
            >
                <el-select
                    v-model="formData.isDisabled"
                    placeholder="请选择是否禁用"
                    clearable
                    :style="{ width: '100%' }"
                >
                    <el-option
                        v-for="(item, index) in isDisabledOptions"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                    ></el-option>
                </el-select>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="单价精度"
                prop="priceAccuracy"
            >
                <el-input
                    v-model="formData.priceAccuracy"
                    placeholder="请输入单价精度"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
            <el-form-item
                label-width="200px"
                label="单据显示货币符号"
                prop="showFlag"
            >
                <el-input
                    v-model="formData.showFlag"
                    placeholder="请输入单据显示货币符号"
                    clearable
                    :style="{ width: '100%' }"
                >
                </el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import { add } from "@/api/base/data";
import { editKingBaseCurrencyList,updataKingBaseCurrencyList } from "@/api/bim/outher";
export default {
    components: {},
     props: ["id"],
    data() {
        return {
            falg:false,
            formData: {
                amountAccuracy: undefined,
                code: undefined,
                currencyName: undefined,
                currencySymbol: undefined,
                dataStatus: undefined,
                isDisabled: undefined,
                priceAccuracy: undefined,
                showFlag: undefined,
            },
            rules: {
                amountAccuracy: [
                    {
                        required: true,
                        message: "请输入金额精度",
                        trigger: "blur",
                    },
                ],
                code: [
                    {
                        required: true,
                        message: "请输入币别编码",
                        trigger: "blur",
                    },
                ],
                currencyName: [
                    {
                        required: true,
                        message: "请输入币别名称",
                        trigger: "blur",
                    },
                ],
                currencySymbol: [
                    {
                        required: true,
                        message: "请输入货币代码",
                        trigger: "blur",
                    },
                ],
                dataStatus: [
                    {
                        required: true,
                        message: "请选择数据状态",
                        trigger: "change",
                    },
                ],
                isDisabled: [
                    {
                        required: true,
                        message: "请选择是否禁用",
                        trigger: "change",
                    },
                ],
                priceAccuracy: [
                    {
                        required: true,
                        message: "请输入单价精度",
                        trigger: "blur",
                    },
                ],
                showFlag: [
                    {
                        required: true,
                        message: "请输入单据显示货币符号",
                        trigger: "blur",
                    },
                ],
            },
            dataStatusOptions: [
                {
                    label: "创建",
                    value: 1,
                },
                {
                    label: "审核中",
                    value: 2,
                },
                {
                    label: "已审核",
                    value: 3,
                },
            ],
            isDisabledOptions: [
                {
                    label: "是",
                    value: 1,
                },
                {
                    label: "否",
                    value: 2,
                },
            ],
        };
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {
        if (this.id!='') {
            this.falg=true
            updataKingBaseCurrencyList(this.id).then((res)=>{
               this.formData=res.data
            })
        }
    },
    methods: {
        submitForm(cb) {
            if (this.falg) {
                this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                editKingBaseCurrencyList(this.formData, "KingBaseCurrency").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("修改成功");
                    }
                });
            });
            }else{
                this.$refs["elForm"].validate((valid) => {
                if (!valid) return;
                // TODO 提交表单
                add(this.formData, "KingBaseCurrency").then((res) => {
                    if (res.code === 200) {
                        cb();
                        this.$message.success("新增成功");
                    }
                });
            });
            }
            
        },
        resetForm() {
            this.$refs["elForm"].resetFields();
        },
    },
};
</script>
<style></style>
